package karaokestrong.servlets;

import java.io.IOException;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import karaokestrong.excepcion.DAOExcepcion;
import karaokestrong.modelo.Cliente;
import karaokestrong.modelo.Reserva;
import karaokestrong.modelo.Sala;
import karaokestrong.negocio.GestionCliente;
import karaokestrong.negocio.GestionReserva;

/**
 * Servlet implementation class ServletReservaInsertar
 */
@WebServlet("/ServletReservaInsertar")
public class ServletReservaInsertar extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletReservaInsertar() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		GestionReserva reserva = new GestionReserva();
	//GestionCliente clienteReg = new GestionCliente();
		
		try{
		
		Reserva res = new Reserva();
		
		//res.setId(Integer.parseInt(request.getParameter("idreserva")));
		res.setFecha(Timestamp.valueOf(request.getParameter("fechayhora")));
		res.setDescripcion(request.getParameter("descripcion"));
		res.setElog(Boolean.parseBoolean(request.getParameter("false")));
		
		Sala sala = new Sala();
		sala.setIdsala(Integer.parseInt(request.getParameter("txtsala")));
		
		Cliente cliente = new Cliente();
		cliente.setIdcliente(Integer.parseInt(request.getParameter("txtId")));
		
		res.setSala(sala);
		res.setCliente(cliente);
		
		reserva.insertar(res);
		
		request.getRequestDispatcher("mensaje.jsp").forward(request, response);
		

		}
		

		catch (DAOExcepcion e) {
			System.out.println("Fallo la insercion: " + e.getMessage());
			
			response.sendRedirect("errorlogin.jsp");
		}
		 
		
	}
		

}
